package com.ssyt.hiring.talent.dao;

import java.util.ArrayList;
import java.util.List;

import com.ssyt.hiring.common.util.DBUtil;
import com.ssyt.hiring.talent.entity.TalentEntity;

public class TalentDao {

	/**
	 * 求职者注册
	 * 
	 * @param talentEntity
	 * @return
	 */
	public int resiter(TalentEntity talentEntity) {
		String sql = "INSERT INTO talent VALUES (NULL,?,?,?,?,?,?,?,?,NULL,NULL)";
		List<Object> paramList = new ArrayList<>();
		paramList.add(talentEntity.getCode());
		paramList.add(talentEntity.getPassword());
		paramList.add(talentEntity.getName());
		paramList.add(talentEntity.getPhone());
		paramList.add(talentEntity.getEmail());
		paramList.add(talentEntity.getAge());
		paramList.add(talentEntity.getGender());
		paramList.add(talentEntity.getHobby());
		return DBUtil.executeUpdate(sql, paramList);
	}

	/**
	 * 求职者登录
	 * 
	 * @param code
	 * @param password
	 * @return
	 */
	public TalentEntity login(String code, String password) {
		String sql = "SELECT * FROM talent WHERE code=? AND password=?";
		return DBUtil.getUniqueResult(TalentEntity.class, sql, code, password);
	}

	/**
	 * 修改密码
	 * 
	 * @param pwd1
	 * @return
	 */
	public int updatepwd(int id, String pwd1, String pwd) {
		String sql = "UPDATE talent SET password=? where id=? and password=?";
		return DBUtil.executeUpdate(sql, pwd1, id, pwd);
	}

	/**
	 * 修改个人信息
	 * 
	 * @param talentEntity
	 * @return
	 */
	public int updateuser(TalentEntity talentEntity) {
		String sql = "UPDATE talent SET name=?,phone=?,email=?,age=?,gender=?,hobby=? where id=?";
		List<Object> paramList = new ArrayList<>();
		paramList.add(talentEntity.getName());
		paramList.add(talentEntity.getPhone());
		paramList.add(talentEntity.getEmail());
		paramList.add(talentEntity.getAge());
		paramList.add(talentEntity.getGender());
		paramList.add(talentEntity.getHobby());
		paramList.add(talentEntity.getId());
		return DBUtil.executeUpdate(sql, paramList);
	}

	/**
	 * 查询个人资料
	 * 
	 * @param id
	 * @return
	 */
	public TalentEntity list(int id) {
		String sql = "SELECT name,phone,email,age,gender,hobby FROM talent WHERE id=?";
		return DBUtil.getUniqueResult(TalentEntity.class, sql, id);
	}

}
